{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "got here\n"
     ]
    }
   ],
   "source": [
    "import inspect\n",
    "import sys\n",
    "import traceback\n",
    "\n",
    "import spacy\n",
    "import spacy.language\n",
    "\n",
    "try:\n",
    "    class MyComponent:\n",
    "        def __init__(self, some_setting):\n",
    "            print(\"got here\")\n",
    "\n",
    "    @spacy.language.Language.factory(\"my_component\", default_config={\"some_setting\": True})\n",
    "    def my_component(nlp, name, some_setting: bool):\n",
    "        return MyComponent(some_setting=some_setting)\n",
    "\n",
    "    nlp = spacy.blank(\"en\")\n",
    "    nlp.add_pipe(\"my_component\", config={\"some_setting\": False})\n",
    "except Exception:\n",
    "    traceback.print_exc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "## Info about spaCy\n",
      "\n",
      "- **spaCy version:** 3.0.5\n",
      "- **Platform:** Darwin-17.7.0-x86_64-i386-64bit\n",
      "- **Python version:** 3.7.9\n",
      "- **Pipelines:** en_core_web_sm (3.0.0)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "!python -m spacy info --markdown"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/Users/paco/src/pytextrank/venv/bin/python3'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sys.executable"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Signature (vocab: Union[spacy.vocab.Vocab, bool] = True, *, max_length: int = 1000000, meta: Dict[str, Any] = {}, create_tokenizer: Union[Callable[[ForwardRef('Language')], Callable[[str], spacy.tokens.doc.Doc]], NoneType] = None, batch_size: int = 1000, **kwargs) -> None>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sig = inspect.signature(spacy.language.Language)\n",
    "sig"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chardet.enums LanguageFilter <class 'chardet.enums.LanguageFilter'>\n",
      "<class 'type'>\n",
      "chardet.escprober LanguageFilter <class 'chardet.enums.LanguageFilter'>\n",
      "<class 'type'>\n",
      "chardet.universaldetector LanguageFilter <class 'chardet.enums.LanguageFilter'>\n",
      "<class 'type'>\n",
      "requests.packages.chardet.enums LanguageFilter <class 'chardet.enums.LanguageFilter'>\n",
      "<class 'type'>\n",
      "requests.packages.chardet.escprober LanguageFilter <class 'chardet.enums.LanguageFilter'>\n",
      "<class 'type'>\n",
      "requests.packages.chardet.universaldetector LanguageFilter <class 'chardet.enums.LanguageFilter'>\n",
      "<class 'type'>\n",
      "spacy Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy language <module 'spacy.language' from '/Users/paco/src/pytextrank/venv/lib/python3.7/site-packages/spacy/language.py'>\n",
      "<class 'module'>\n",
      "spacy.cli.debug_data Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.cli.init_pipeline Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.cli.profile Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.lang.en Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.lang.xx Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.lang.xx MultiLanguage <class 'spacy.lang.xx.MultiLanguage'>\n",
      "<class 'type'>\n",
      "spacy.language Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.lookups load_language_data <function load_language_data at 0x10e8ca0e0>\n",
      "<class 'function'>\n",
      "spacy.ml build_masked_language_model <function build_masked_language_model at 0x10f3dee60>\n",
      "<class 'function'>\n",
      "spacy.ml.models build_masked_language_model <function build_masked_language_model at 0x10f3dee60>\n",
      "<class 'function'>\n",
      "spacy.ml.models.multi_task build_masked_language_model <function build_masked_language_model at 0x10f3dee60>\n",
      "<class 'function'>\n",
      "spacy.pipeline.attributeruler Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.dep_parser Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.entity_linker Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.entityruler Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.functions Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.lemmatizer Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.morphologizer Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.ner Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.pipe Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.sentencizer Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.senter Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.tagger Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.textcat Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.textcat_multilabel Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.tok2vec Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.pipeline.trainable_pipe Language <class 'spacy.language.Language'>\n",
      "<class 'type'>\n",
      "spacy.symbols LANGUAGE 389\n",
      "<class 'int'>\n",
      "spacy.training.converters.json_to_docs MultiLanguage <class 'spacy.lang.xx.MultiLanguage'>\n",
      "<class 'type'>\n",
      "spacy.util load_language_data <function load_language_data at 0x10e8ca0e0>\n",
      "<class 'function'>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Traceback (most recent call last):\n",
      "  File \"<ipython-input-5-06c1a9fe0246>\", line 5, in <module>\n",
      "    for mem_name, mem_obj in inspect.getmembers(mod_obj):\n",
      "  File \"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py\", line 341, in getmembers\n",
      "    value = getattr(object, key)\n",
      "  File \"/Users/paco/src/pytextrank/venv/lib/python3.7/site-packages/urllib3/packages/six.py\", line 91, in __get__\n",
      "    result = self._resolve()\n",
      "  File \"/Users/paco/src/pytextrank/venv/lib/python3.7/site-packages/urllib3/packages/six.py\", line 113, in _resolve\n",
      "    return _import_module(self.mod)\n",
      "  File \"/Users/paco/src/pytextrank/venv/lib/python3.7/site-packages/urllib3/packages/six.py\", line 82, in _import_module\n",
      "    __import__(name)\n",
      "  File \"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/dbm/gnu.py\", line 3, in <module>\n",
      "    from _gdbm import *\n",
      "ModuleNotFoundError: No module named '_gdbm'\n",
      "Traceback (most recent call last):\n",
      "  File \"<ipython-input-5-06c1a9fe0246>\", line 5, in <module>\n",
      "    for mem_name, mem_obj in inspect.getmembers(mod_obj):\n",
      "  File \"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py\", line 341, in getmembers\n",
      "    value = getattr(object, key)\n",
      "  File \"/Users/paco/src/pytextrank/venv/lib/python3.7/site-packages/six.py\", line 92, in __get__\n",
      "    result = self._resolve()\n",
      "  File \"/Users/paco/src/pytextrank/venv/lib/python3.7/site-packages/six.py\", line 115, in _resolve\n",
      "    return _import_module(self.mod)\n",
      "  File \"/Users/paco/src/pytextrank/venv/lib/python3.7/site-packages/six.py\", line 82, in _import_module\n",
      "    __import__(name)\n",
      "  File \"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/dbm/gnu.py\", line 3, in <module>\n",
      "    from _gdbm import *\n",
      "ModuleNotFoundError: No module named '_gdbm'\n",
      "Traceback (most recent call last):\n",
      "  File \"<ipython-input-5-06c1a9fe0246>\", line 5, in <module>\n",
      "    for mem_name, mem_obj in inspect.getmembers(mod_obj):\n",
      "  File \"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py\", line 341, in getmembers\n",
      "    value = getattr(object, key)\n",
      "  File \"/Users/paco/src/pytextrank/venv/lib/python3.7/site-packages/urllib3/packages/six.py\", line 91, in __get__\n",
      "    result = self._resolve()\n",
      "  File \"/Users/paco/src/pytextrank/venv/lib/python3.7/site-packages/urllib3/packages/six.py\", line 113, in _resolve\n",
      "    return _import_module(self.mod)\n",
      "  File \"/Users/paco/src/pytextrank/venv/lib/python3.7/site-packages/urllib3/packages/six.py\", line 82, in _import_module\n",
      "    __import__(name)\n",
      "  File \"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/dbm/gnu.py\", line 3, in <module>\n",
      "    from _gdbm import *\n",
      "ModuleNotFoundError: No module named '_gdbm'\n"
     ]
    }
   ],
   "source": [
    "targets = []\n",
    "\n",
    "for mod_name, mod_obj in sorted(sys.modules.items()):\n",
    "    try:\n",
    "        for mem_name, mem_obj in inspect.getmembers(mod_obj):\n",
    "            if \"language\" in mem_name.lower():\n",
    "                print(mod_name, mem_name, mem_obj)\n",
    "                print(type(mem_obj))\n",
    "                \n",
    "                if mem_name is \"Language\":\n",
    "                    targets.append((mod_name, mem_name, mem_obj))\n",
    "    except Exception:\n",
    "        traceback.print_exc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('spacy', 'Language', spacy.language.Language),\n",
       " ('spacy.cli.debug_data', 'Language', spacy.language.Language),\n",
       " ('spacy.cli.init_pipeline', 'Language', spacy.language.Language),\n",
       " ('spacy.cli.profile', 'Language', spacy.language.Language),\n",
       " ('spacy.lang.en', 'Language', spacy.language.Language),\n",
       " ('spacy.lang.xx', 'Language', spacy.language.Language),\n",
       " ('spacy.language', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.attributeruler', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.dep_parser', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.entity_linker', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.entityruler', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.functions', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.lemmatizer', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.morphologizer', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.ner', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.pipe', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.sentencizer', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.senter', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.tagger', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.textcat', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.textcat_multilabel', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.tok2vec', 'Language', spacy.language.Language),\n",
       " ('spacy.pipeline.trainable_pipe', 'Language', spacy.language.Language)]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "targets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "spacy Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.cli.debug_data Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.cli.init_pipeline Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.cli.profile Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.lang.en Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.lang.xx Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.language Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.attributeruler Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.dep_parser Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.entity_linker Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.entityruler Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.functions Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.lemmatizer Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.morphologizer Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.ner Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.pipe Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.sentencizer Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.senter Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.tagger Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.textcat Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.textcat_multilabel Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.tok2vec Language <class 'spacy.language.Language'>\n",
      "True\n",
      "spacy.pipeline.trainable_pipe Language <class 'spacy.language.Language'>\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "for mod_name, mem_name, mem_obj in targets:\n",
    "    print(mod_name, mem_name, mem_obj)\n",
    "    print(hasattr(mem_obj, \"factory\"))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
